home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2005 May / CyberMycha 05-2005 (Poland).bin / Immortal / cotndemo.exe / Data1.cab / generic_attack.tai < prev    next >
Encoding:
Text File  |  2004-11-16  |  4.8 KB  |  149 lines

  1. //
  2. //    Generic Attack AI file
  3. //
  4. //    Behaviors:
  5. //
  6. //        When idle, periodically look for an enemy unit to attack.
  7. //        Attempt to keep target in weapon range by moving and/or facing when target moves.
  8. //        Return to idle state when target dies or moves out of LOS.
  9. //
  10. //    Notes:
  11. //
  12. //        When using this file with the Generic Movement AI file, you should include this file first.
  13. //            Failure to do so will result in units that don't stop when in weapon range or when
  14. //            their target dies.  Your unit will look stupid.
  15. //
  16. //    Common modifications:
  17. //
  18. //        To abort the attack early with a new trigger, insert a new AttackEnemyUnit and
  19. //            FaceEnemyUnit transition specification before including this file.
  20. //        To prevent pursuit of fleeing enemies, place new FaceEnemyUnit:UnitNotInWeaponRange
  21. //            and AttackEnemyUnit:UnitNotInWeaponRange transition specifications after
  22. //            including this file.
  23. //        To prevent following a faster target, place a new ReacquireGoal:GoalIsUnit transition
  24. //            specification after including this file.
  25. //
  26. //    Known Problems:
  27. //
  28. //    Usage:
  29. //
  30. //        To tell a unit to attack another unit, give it an attack goal (EEUGAttackUnit or EEUGAttackGround)
  31. //            and set it's action to keeuaAttackEnemyUnit.
  32. //
  33.  
  34. // any good targets around?
  35. Idle
  36. {    
  37.     CanISeeEnemy true(CheckRange)
  38.     // we no longer poll to see if we're under attack - notification comes from EEUnit::TakeDamage()
  39. }
  40.  
  41. // is the target in weapon range already?
  42. CheckRange
  43. {
  44.     anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
  45.     allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
  46.     UnitInWeaponRange true(FaceEnemyUnit) 
  47.     anyof(CanIMoveFreely,GoalIsPlayerInitiated) true(ShouldIFollowEnemyUnit) false(ShouldIReturnToInitialContactLocation)
  48. }
  49.  
  50. // stop moving toward the target if we achieve weapon range
  51. GetNextMoveWaypoint
  52. {
  53.     anyof(EnemyUnitDestroyed,CeaseFire) true(ShouldIReturnToInitialContactLocation)
  54.     allof(AttackerIsRangedUnit,UnitInWeaponRange) true(FaceEnemyUnit)
  55.     EnemyUnitMoved true(CheckRange)
  56. }
  57.  
  58. // should I follow the enemy unit? 
  59. ShouldIFollowEnemyUnit
  60. {
  61.     allof(OneWaypointRemaining,GoalIsUnit,EnemyUnitHasNotMovedOneTile) true(Advance)
  62.     anyof(CanIPursuePastInitialContactLOS,EnemyInsideInitialContactLOS,GoalIsPlayerInitiated) true(PrepareToMove) false(ShouldIReturnToInitialContactLocation)
  63. }
  64.  
  65. // face our target until it is destroyed or moves
  66. FaceEnemyUnit
  67. {
  68.     ShouldIRun true(RunFromAttacker)
  69.     anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
  70.     allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
  71.     UnitInWeaponRange false(CheckRange)
  72.     allof(TargetIsSpecialEnemy,Reloaded,EnemyUnitInsideFiringArch) true(ChangeTargetForSpecialEnemy)
  73.     allof(Reloaded,EnemyUnitInsideFiringArch) true(AttackEnemyUnit)
  74.     FacingEnemyUnit true(WaitForReload)
  75. }
  76.  
  77. ChangeTargetForSpecialEnemy
  78. {
  79.     AlwaysTrue true(ReacquireGoal)
  80. }
  81.  
  82. // attack the target until it is destroyed or moves
  83. AttackEnemyUnit
  84. {
  85.     ShouldIRun true(RunFromAttacker)
  86.     ShouldIRetaliate true(RetaliateAgainstAttacker)
  87.     EnemyUnitInsideFiringArch false(FaceEnemyUnit)
  88.     AlwaysTrue true(WaitForReload)
  89. }
  90.  
  91.  
  92. // face our target until it is destroyed or moves
  93. FaceLocation
  94. {
  95.     ShouldIRun true(RunFromAttacker)
  96.     ShouldIRetaliate true(RetaliateAgainstAttacker)
  97.     CeaseFire true(Idle)
  98.     LocationInWeaponRange false(PrepareToMove)
  99.     LocationInsideFiringArch true(WaitForReload)
  100. }
  101.  
  102. // wait for reload - this guarentees that we get at least 1 attack off 
  103. WaitForReload
  104. {
  105.     ShouldIRun true(RunFromAttacker)
  106.     ShouldIRetaliate true(RetaliateAgainstAttacker)
  107.     Reloaded true(FaceEnemyUnit)
  108.     anyof(EnemyUnitDestroyed,CeaseFire,UnitNotOnMap,EnemyWithinMinimumRange) true(ShouldIReturnToInitialContactLocation)
  109.     allof(EnemyUnitNoLongerVisible,GoalIsNotPlayerInitiated) true(ShouldIReturnToInitialContactLocation)
  110. }
  111.  
  112. // attack the target until it is destroyed or moves
  113. InitialAttackState
  114. {
  115.     //Reloaded false(WaitForReload)
  116.     GoalIsUnit true(FaceEnemyUnit)
  117. }
  118.  
  119. // ReAcquire Goal
  120. // BlockedByWall needs to come first
  121. // Followed by the tests for the various possible goals
  122.  
  123. ReacquireGoal
  124. {
  125.     BlockedByWall true(ShouldIReturnToInitialContactLocation)
  126.     GoalIsUnit true(ReacquireEnemyUnit)
  127. }
  128.  
  129. ReacquireEnemyUnit
  130. {
  131.     EnemyUnitReachable true(CheckRange) false(ShouldIReturnToInitialContactLocation)
  132. }
  133.  
  134. RetaliateAgainstAttacker
  135. {
  136.     GoalIsUnit true(CheckRange) false(PrepareToMove)
  137. }
  138.  
  139. RunFromAttacker
  140. {
  141.     AlwaysTrue true(PrepareToMove)
  142. }
  143.  
  144. UnderAttack
  145. {
  146.     CanFlee true(RunFromAttacker)
  147.     allof(CanITargetEnemies,UnitIdleOrAttackingDefenselessBuilding,IsAttackerInRetaliationRange,CanDamageAttacker,AttackerIsReachable) true(RetaliateAgainstAttacker) false(ReacquireGoal)
  148. }
  149.